<div class="view">
<fieldset id="saved_report" class="ui-widget section">
<legend	class="ui-widget-header ui-corner-all">Saved Report</legend>
	<?php 
		$report = $model->report();
		if(count($report) == 0)
			echo "No report is being generated yet";
	?> 
	<?php foreach($report as $_report): ?>
	<div>
		<?php CHtml::link(CHtml::encode($_report->subject),CHtml::normalizeUrl(array('packing_list/viewreport','id'=>$_report->id))); ?>
	</div>
	<?php endforeach; ?>	
</fieldset>
<fieldset id="new_report" class="ui-widget section">
	<legend class="ui-widget-header ui-corner-all">New Report</legend>
	<div class="wide form">
		<div class="row" style="width: 100%;">
			<div class="col">
				<?php echo CHtml::dropDownList('reportType',0,$this->makeReportList());?>
			</div>
			<div class="col">
				<?php $this->widget('application.widgets.listicon.ListIcon',array(
                    'icons'=>array(
						array('value'=>'Preview report','icon'=>'ui-icon-note','needtext'=>"true"),
						array('value'=>'Generate report','icon'=>'ui-icon-note','needtext'=>"true"),
					),
					'id'=>'generate_report',
				));?>
			</div>
		</div>
	</div>
	<hr />
	<div class="row">
	</div>
</fieldset>
</div>
<?php
$cs = Yii::app()->getClientScript();
$viewReportURL = CHtml::normalizeUrl(array('report/render','m'=>'packing_list','t'=>'packing_list_report','id'=>$model->id));
$NewPackageURL = CHtml::normalizeUrl(array('packing_list/NewPackage','packing_list_id'=>$model->id));
$s =<<<EOD
$('div#generate_report a:eq(0)').click(function(){
	var select = $(this).parents('div.row').find('select').val();
	var container = $('fieldset#new_report>div:eq(1)');
	$(container).subcontent({
		url:'$viewReportURL?r='+select
	});
});
$('div#generate_report a:eq(1)').click(function(){
	var select = $(this).parents('div.row').find('select').val();
	window.open('$viewReportURL?type=pdf&r='+select,'report_window','toolbar=0,location=0,menubar=0');
});
EOD;
$cs->registerScript('packing_list#view',$s);
?>